import history from "@/utils/history";
import { hasToken } from "@/utils/storage";
import React from "react";
import { Redirect, Route } from "react-router-dom";

// 定义属性类型
type Prop = {
  // 要访问的页面的路径
  path: string;
  // 要显示的路由组件
  component: React.FC;
};

export default function AuthRoute({ path, component: Component }: Prop) {
  // console.log(path);
  return (
    <Route
      path={path}
      render={() => {
        return hasToken() ? (
          <Component />
        ) : (
          <Redirect to={`/login?from=${path}`} />
        );
      }}
    />
  );
}
